package com.pxst.bank.controller;

import com.pxst.annotations.LogOperate;
import com.pxst.bank.entity.SysBankServiceTimeEntity;
import com.pxst.bank.req.ServiceTimeAddReq;
import com.pxst.bank.req.ServiceTimeReq;
import com.pxst.bank.resp.SysBankServiceTimeResp;
import com.pxst.bank.service.SysBankServiceTimeService;
import com.pxst.resp.ApiResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description 银行账户管理-暂停时间表设定相关接口
 */
@RestController
@RequestMapping("/api/serviceTime")
@Api(tags = "暂停时间表设定相关接口")
@Slf4j
public class SysServiceTimeController {

    @Resource
    private SysBankServiceTimeService sysBankServiceTimeService;

    @GetMapping("/search")
    @ApiOperation("暂停时间设定-列表（条件查询）")
    public ApiResp<List<SysBankServiceTimeResp>> getServiceTimeByCondition(ServiceTimeReq serviceTimeReq) {
        log.info("serviceTimeReq 查询的信息为：{}", serviceTimeReq);
        ApiResp<List<SysBankServiceTimeResp>> respList = sysBankServiceTimeService.getServiceTimeByCondition(serviceTimeReq);
        log.info("返回的结果为:{}", respList);
        return ApiResp.sucess(respList);
    }

    @PutMapping("/{id}")
    @ApiOperation("暂停时间表设定-修改状态")
    @LogOperate(operate = "暂停时间表编辑", service = SysBankServiceTimeService.class, type = "edit")
    public ApiResp<String> updateStatusById(@PathVariable Long id, Integer status) {
        log.info("id:{},status:{}", id, status);
        ApiResp<String> resp = sysBankServiceTimeService.updateStatusById(id, status);
        return ApiResp.sucess(resp);
    }

    @PostMapping
    @ApiOperation("暂停时间表设定-新增")
    @LogOperate(operate = "暂停时间表-新增", service = SysBankServiceTimeService.class, type = "add")
    public ApiResp<SysBankServiceTimeEntity> save(@RequestBody ServiceTimeAddReq serviceTimeAddReq) {
        log.info("添加的对象信息:{}", serviceTimeAddReq);
        ApiResp<SysBankServiceTimeEntity> resp = sysBankServiceTimeService.saveServiceTime(serviceTimeAddReq);
        log.info("返回的信息:{}", resp);
        return ApiResp.sucess(resp);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("暂停时间表设定-删除")
    @LogOperate(operate = "暂停时间表设定-删除", service = SysBankServiceTimeService.class, type = "delete")
    public ApiResp<String> deleteById(@PathVariable Long id) {
        log.info("要删除的对象id:{}", id);
        ApiResp<String> resp = sysBankServiceTimeService.deleteById(id);
        return ApiResp.sucess(resp);
    }
}
